﻿using System;
using System.Collections.Generic;
using System.Text;

namespace 设计模式
{
    public class lianheguo
    {

        public static void main() {
            unite_nation_security unsc = new unite_nation_security();
            usa c1 = new usa(unsc);
            iraq c2 = new iraq(unsc);

            unsc.c1 = c1;
            unsc.c2 = c2;

            c1.declare("不准研制核武器，否则要发动战争");
            c2.declare("我们没有核武器，也不怕侵略");

            Console.Read();
        }

    }

    class unite_nation
    {
        public virtual void declare(string message, country colleague) { }
    }

    class country
    {
        public unite_nation mediator;

        public country(unite_nation mediator)
        {
            this.mediator = mediator;
        }
    }

    class usa : country
    {
        public usa(unite_nation mediator) : base(mediator) { }

        public void declare(string message)
        {
            mediator.declare(message, this);
        }

        public void getmessage(string message)
        {
            Console.WriteLine("美国获得对方信息：" + message);
        }
    }

    class iraq : country
    {
        public iraq(unite_nation mediator) : base(mediator) { }

        public void declare(string message)
        {
            mediator.declare(message, this);
        }

        public void getmessage(string message)
        {
            Console.WriteLine("伊拉克获得对方信息：" + message);
        }
    }

    class unite_nation_security : unite_nation
    {
        public usa c1;
        public iraq c2;

        public override void declare(string message, country colleague)
        {
            if (colleague == c1)
            {
                c2.getmessage(message);
            }
            else
            {
                c1.getmessage(message);
            }
        }
    }

}
